<?php $this->_extends('../_layouts/default_layout');?>
<?php $this->_block('contents');?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/prettyphoto.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.prettyphoto.js"></script>
<script type="text/javascript">
$(function(){
	$("a[rel^='pretty_photo']").prettyPhoto({theme:'facebook'});
	$("#tabs").tabs();
	$(".datepicker").datepicker({dateFormat: 'yy-mm-dd', changeMonth: true});
	$(".message_template").change(function(){
		var current_tag = $(this);
		$.ajax({
			type: "GET",
			url: "<?=url('Services::EbayCase/MessageTemplateAjax')?>&id=" + $(this).val(),
			dataType: "text",
			success:
				function(data)
				{
					current_tag.parent().next().children("textarea").val(data);
				}
		});
	});
	$(".solution_btn").click(function(){
		var solution = $(this).parent().parent("form").children("input[name='solution']").val();
		if (solution == <?=Q::ini('custom_flag/services_ebay_case_response_solution/issueFullRefund/value')?>)
		{
			if ( ! confirm('确定提供全额退款？'))
			{
				return false;
			}
		}
		if (solution == <?=Q::ini('custom_flag/services_ebay_case_response_solution/offerPartialRefund/value')?>)
		{
			var amount = $(this).parent().parent("form").find("input[name='amount']").val();
			if ( ! confirm('确定部分退款，退款金额为：<?=$case['currency_symbol']?>' + amount + '？'))
			{
				return false;
			}
		}
		if (solution == <?=Q::ini('custom_flag/services_ebay_case_response_solution/offerRefundUponReturn/value')?>)
		{
			if ( ! confirm('确定提供退货退款？'))
			{
				return false;
			}
		}
		$(this).attr('disabled', true);
		$(this).next().show();
		$(this).parent().parent("form").submit();
	});
});
</script>
<table width="100%">
<tr>
	<td width="60%" valign="top">
		<table class="list_table" width="100%" style="text-align: left">
		<tr>
			<th width="15%">纠纷编号</th>
			<td><?=$case['case_id']?></td>
		</tr>
		<tr>
			<th>商品标题</th>
			<td><?=isset($listing[0]['title']) ? $listing[0]['title'] : ''?></td>
		</tr>
		<tr>
			<th>ItemID</th>
			<td><?=$case['shop_item_id']?></td>
		</tr>
		<tr>
			<th>店铺名称</th>
			<td><?=$case['shop_name']?></td>
		</tr>
		<tr>
			<th>买家账号</th>
			<td><?=$case['buyer']?></td>
		</tr>
		<tr>
			<th>买家期待</th>
			<td><?=$case['expectation']?></td>
		</tr>
		<tr>
			<th>创建原因</th>
			<td><?=$case['reason']?></td>
		</tr>
		<tr>
			<th>总金额</th>
			<td><?=$case['currency_symbol']?> <?=sprintf('%.2f', $case['amount'])?></td>
		</tr>
		<tr>
			<th>产品数量</th>
			<td><?=$case['quantity']?></td>
		</tr>
		<tr>
			<th>类型</th>
			<td><?=Helper_BSS_Normal::getIniOne('services_ebay_case_type', 'value', $case['type'], 'name')?></td>
		</tr>
		<tr>
			<th>状态</th>
			<td><?=$case['status']?></td>
		</tr>
		<tr>
			<th>交易时间</th>
			<td><?=$case['transaction_time']?></td>
		</tr>
		<tr>
			<th>纠纷日期</th>
			<td><?=$case['create_time']?></td>
		</tr>
		<tr>
			<th>更新日期</th>
			<td><?=$case['update_time']?></td>
		</tr>
		<?if (in_array($case['type'], array(Q::ini('custom_flag/services_ebay_case_type/EBP_INR/value'), Q::ini('custom_flag/services_ebay_case_type/EBP_SNAD/value')))):?>
		<tr>
			<th valign="top">解决方案</th>
			<td>
				<div id="tabs">
					<ul style="background: #eeeeee">
						<?$method = explode('-', Helper_BSS_Normal::getIniOne('services_ebay_case_type', 'value', $case['type'], 'response'))?>
						<?foreach ($method as $m):?>
						<li><a href="<?='#' . Helper_BSS_Normal::getIniOne('services_ebay_case_response_solution', 'value', $m, 'method')?>"><?=Helper_BSS_Normal::getIniOne('services_ebay_case_response_solution', 'value', $m, 'name')?></a></li>
						<?endforeach;?>
					</ul>
					<?foreach ($method as $m):?>
					<div id="<?=Helper_BSS_Normal::getIniOne('services_ebay_case_response_solution', 'value', $m, 'method')?>">
						<form method="post" action="<?=url('Services::EbayCase/Solution')?>">
							<input type="hidden" name="solution" value="<?=$m?>" />
							<input type="hidden" name="services_ebay_case_id" value="<?=$_GET['id']?>" />
							<?if ($m == Q::ini('custom_flag/services_ebay_case_response_solution/provideShippingInfo/value')):?>
							<p style="text-indent: 12px"><span>承运商： </span><input type="text" name="shipping_carrier" /></p>
							<p><span>运输时间： </span><input type="text" class="datepicker" name="shipped_time" /></p>
							<?endif;?>
							<?if ($m == Q::ini('custom_flag/services_ebay_case_response_solution/provideTrackingInfo/value')):?>
							<p style="text-indent: 12px;"><span>承运商： </span><input type="text" name="shipping_carrier" /></p>
							<p style="text-indent: 12px;"><span>追踪号： </span><input type="text" name="tracking_number" /></p>
							<?endif;?>
							<?if ($m == Q::ini('custom_flag/services_ebay_case_response_solution/issueFullRefund/value')):?>
							<p><span>退款金额： </span><strong><?=$case['currency_symbol']?></strong> <input type="text" value="<?=sprintf('%.2f', $case['amount'])?>" disabled="disabled" size="10" /></p>
							<?endif;?>
							<?if ($m == Q::ini('custom_flag/services_ebay_case_response_solution/offerPartialRefund/value')):?>
							<p><span>退款金额：  </span><strong><?=$case['currency_symbol']?></strong> <input type="text" name="amount" value="" size="10" /></p>
							<?endif;?>
							<?if ($m != Q::ini('custom_flag/services_ebay_case_response_solution/offerRefundUponReturn/value')):?>
							<p>
								<span>留言模板：</span>
								<select class="message_template">
									<option value="0">--请选择--</option>
									<?foreach ($message_template as $mt):?>
									<option value="<?=$mt['id']?>"><?=$mt['name']?></option>
									<?endforeach;?>
								</select>
							</p>
							<p style="text-indent: 24px"><span style="vertical-align: top">留言： </span><textarea rows="6" name="message" style="width: 80%"></textarea></p>
							<?endif;?>
							<?if ($m == Q::ini('custom_flag/services_ebay_case_response_solution/offerRefundUponReturn/value')):?>
							<?$address = Q::ini('custom_flag/services_ebay_case_response_return_address/address1');?>
							<strong>return address:</strong>
							<div style="padding-left: 20px;">
								<?=$address['name']?><br />
								<?=$address['street1']?><br />
								<?=$address['city']?> <?=$address['state']?> <?=$address['postal']?><br />
								<?=$address['country']?>
							</div>
							<?endif;?>
							<input type="hidden" name="<?=Q::ini('unique_token_name')?>" value="<?=Helper_BSS_Normal::genToken()?>" />
							<p style="text-indent: 62px"><input type="button" class="button solution_btn" value="提交" /> <img src="<?=Q::ini('custom_system/base_url')?>img/loading.gif" style="display: none" /></p>
						</form>
					</div>
					<?endforeach;?>
				</div>
			</td>
		</tr>
		<?endif;?>
		</table>
	</td>
	<td width="15px"></td>
	<td valign="top">
		<table class="list_table" width="100%"><tr><th><?=('ItemID（' . (isset($listing[0]['item_id']) ? $listing[0]['item_id'] : '') . '）的')?>上架产品信息</th></tr></table>
		<div style="overflow-y: auto; <?=((count($listing)>5) ? 'height: 190px;' : '')?>width: 100%;">
		<table width="100%" class="list_table">
			<tr>
				<th>SKU</th>
				<th>价格</th>
				<th>上架类型</th>
			</tr>
			<?foreach ($listing as $k => $l):?>
			<tr>
				<td align="left">
					<?if ($l['pic_url']):?>
					<?$pretty_photo_number = 0;?>
					<?foreach ($l['pic_url'] as $lpu):?>
					<a rel="pretty_photo[<?=$l['sku']?>]" href="<?=$lpu?>"><?if (!$pretty_photo_number):?><span class="img_icon"></span><?endif;?></a>
					<?$pretty_photo_number = 1;?>
					<?endforeach;?>
					<?endif;?>
					<?=$l['sku']?>
				</td>
				<td><?=$l['currency_symbol']?><?=sprintf('%.2f', $l['item_start_price'])?></td>
				<td><?=Helper_BSS_Normal::getIniOne('online_ebay_listing_type', 'value', $l['listing_type'], 'name')?></td>
			</tr>
			<?endforeach;?>
		</table>
		</div>
		<br />
		<table width="100%" class="list_table">
			<tr>
				<th colspan="5"><?='顾客（' . $case['buyer'] . '）的'?>购买记录</th>
			</tr>
			<tr>
				<th>订单号</th>
				<th>金额</th>
				<th>数量</th>
				<th>邮寄方式</th>
				<th>销售时间</th>
			</tr>
			<?foreach ($order as $o):?>
			<tr>
				<td><a href="<?=url('Sales::Order/List', array('is_search' => 1, 'number' => $o['number']))?>"><?=$o['number']?></a></td>
				<td><?=$o['symbol'] . sprintf('%.2f', $o['amount'])?></td>
				<td><?=$o['product_quantity']?></td>
				<td><?=$o['shipping_name']?></td>
				<td><?=$o['sales_time']?></td>
			</tr>
			<?endforeach;?>
			<tr>
				<td colspan="5"><a href="<?=url('Sales::Order/List', array('is_search' => 1, 'shop_buyer_id' => $case['buyer']))?>">查看更多</a></td>
			</tr>
		</table>
		<br />
		<table class="list_table" width="100%">
			<tr>
				<th colspan="4">回复历史</th>
			</tr>
			<tr>
				<th width="60px">处理方</th>
				<th>消息</th>
				<th width="80px">发送时间</th>
			</tr>
			<?foreach ($response as $r):?>
			<tr>
				<td><?=$r['author_role']?></td>
				<td align="left" title="描述：<?=$r['description'] . "\n"?>
<?if (! empty($r['shipping_carrier'])):?>承运商：<?=$r['shipping_carrier'] . "\n"?><?endif;?>
<?if (! empty($r['tracking_number'])):?>追踪号：<?=$r['tracking_number'] . "\n"?><?endif;?>
<?if (! empty($r['shipped_time'])):?>运输时间：<?=$r['shipped_time'] . "\n"?><?endif;?>
<?if (! empty($r['refund'])):?>退款金额：<?=$case['currency_symbol']?><?=sprintf('%.2f', $r['refund']) . "\n"?><?endif;?>
<?if (! empty($r['refund_transaction_id'])):?>退款交易ID：<?=$r['refund_transaction_id']?><?endif;?>">
					<div style="word-wrap:break-word; width: 300px;"><?=$r['message']?></div>
				</td>
				<td><?=$r['response_time']?></td>
			</tr>
			<?endforeach;?>
		</table>
	</td>
</tr>
</table>
<?php $this->_endblock();?>